/**
 * 初始化详情对话框
 */
var AccessoryInfoDlg = {
    contactsInfoData : {},
    canSubmit : true,
    accessoryTable : $("#accessoryTable").val(),
    refId : $("#refId").val(),
    accessoryType : $("#accessoryType").val(),
};

/**
 * 清除数据
 */
AccessoryInfoDlg.clearData = function() {
    this.contactsInfoData = {};
}
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
AccessoryInfoDlg.set = function(key, val) {
    this.contactsInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
AccessoryInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
AccessoryInfoDlg.close = function() {
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}

$(function() {
    Feng.initValidator("accessoryInfoForm", AccessoryInfoDlg.validateFields);
    //初始化文件上传
    CiUploader.init({
        accessoryTable:AccessoryInfoDlg.accessoryTable,
        refId:AccessoryInfoDlg.refId,
        accessoryType:AccessoryInfoDlg.accessoryType,
        success: function(file,response ){
            //增加附件列表
            if(response.success){
                $("#accessoryList").append('<div class="form-group" id="accessoryItem'+response.data.id+'">\n' +
                    '    <input type="hidden" name="fileUrl" id="fileUrl'+response.data.id+'" value="'+response.data.fileUrl+'" />\n' +
                    '    <label class="col-sm-2 control-label accessoryItemsLabel"></label>\n' +
                    '    <label class="col-sm-6 control-label" style="text-align: left;white-space: normal; word-wrap: break-word;\n' +
                    '    word-break: break-all;">'+response.data.fileName+'</label>\n' +
                    '    <div class="col-sm-4"  style="text-align: right;">\n' +
                    '        <button type="button" class="btn btn-info" onclick="Feng.eyeAccessory('+response.data.id+')"><i class="fa fa-eye"></i>&nbsp;查看</button>' +
                    '        <button type="button" class="btn btn-danger" onclick="Feng.deleteAccessory('+response.data.id+')"><i class="fa fa-remove"></i>&nbsp;删除</button>' +
                    '    </div>\n' +
                    '</div>')
                $(".accessoryItemsLabel").eq(0).text("已上传的附件：");
            }
        }
    });
});
